package com.lenovo.agricultureclient.ui.dialog;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.view.View;

import com.lenovo.agricultureclient.ClientApp;
import com.lenovo.agricultureclient.R;
/**
 * 设置PM2.5浓度阀值的对话框
 * @author zongbingwu
 *
 */
public class SettingPm25Dialog extends SettingBaseDialog 
{
	public SettingPm25Dialog(Activity act, ClientApp app) {
		super(act, app);
	}

	@Override
	protected void onInitView() {
		super.onInitView();
		mTitleTextView.setText(R.string.pm25_threshold_value_setting);
		//初始化PM2.5相关控件
		mMajorMinLayout.setVisibility(View.INVISIBLE);
		mMajorValueTitleTV.setText(R.string.pm25_current_value);
		mMajorStatusTitleTV.setText(R.string.pm25_current_status);
		mMajorMaxET.setText(mSensorConfig.maxPM25+"");
		//第二部分控件设置不可见
		mSlaveLayout.setVisibility(View.GONE);
	}

	@Override
	protected void onUpateView() {
		super.onUpateView();
		//刷新PM2.5浓度相关控件
		mMajorValueTV.setText(mSensorValue.getPm25()+"");
		if(mSensorValue.getPm25()<mSensorConfig.maxPM25){
			mMajorStatusTV.setText(R.string.normal);
			mMajorStatusTV.setTextColor(Color.BLACK);
		} else {
			mMajorStatusTV.setText(R.string.exception);
			mMajorStatusTV.setTextColor(Color.RED);
		}
	}

	//向服务器端发送设置PM2.5浓度阀值的请求
	@Override
	protected boolean onPostSet(int majorMin, int majorMax, int slaveMin,int slaveMax) {
		mRequest.resetRequest();
		mRequest.setPm25(majorMax);
		startRequest(mRequest);
		return true;
	}
}
